<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8" />
  <title>灵盔佑驰</title>
  <!-- 百度地图API -->
  <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=C81uBynkCqbFp9suE5SZF50pEzlsCyNM"></script>
  <!-- AOS动画库CSS -->
  <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
  <style>
    /* 加载动画 */
    #loading {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 9999;
    }
    
    body {
      font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
      line-height: 1.6;
      color: #333;
      background-color: #f5f7fa;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      overflow-x: hidden;
    }

    /* 导航栏样式 */
    .navbar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20px 40px;
      background-color: #ffffff;
      z-index: 1001;
      position: relative;
    }

    .nav-buttons button {
      margin-left: 15px;
      padding: 10px 20px;
      border: none;
      border-radius: 25px;
      font-size: 1em;
      cursor: pointer;
      transition: transform 0.3s ease;
    }

    .login-btn {
      background-color: #409eff;
      color: white;
    }

    .register-btn {
      background-color: #ff4d4f;
      color: white;
    }

    .nav-buttons button:hover {
      transform: scale(1.05);
      opacity: 0.9;
    }

    /* 系统介绍模块样式 - 统一为传感器主题配色 */
    .intro-container {
      display: flex;
      flex-direction: column;
      margin: 40px auto;
      max-width: 1200px;
      width: 100%;
      border-radius: 20px;
      overflow: hidden;
      /* 统一使用传感器主题的深空蓝与炭黑渐变背景 */
      background: linear-gradient(135deg, #0a0f2c 0%, #000000 100%);
      color: #e0e0e0;
      padding: 60px 40px;
      text-align: center;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
      z-index: 1001;
      position: relative;
      transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .intro-container:hover {
      transform: translateY(-5px);
      box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
      border-color: rgba(0, 247, 255, 0.6);
    }

    .intro-container::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 1px;
      background: linear-gradient(90deg, transparent, #00f7ff, transparent);
    }

    .intro-header h2 {
      font-size: 2.5em;
      font-weight: bold;
      margin-bottom: 20px;
      /* 使用霓虹蓝色 */
      color: #00f7ff;
    }

    .intro-content {
      font-size: 1.2em;
      line-height: 1.8;
      max-width: 1000px;
      margin: 0 auto;
    }

    .intro-content p {
      margin-bottom: 15px;
    }

    /* 传感器数据模块样式*/
    .sensor-container {
      display: flex;
      flex-direction: column;
      margin: 40px 0;
      max-width: 100%;
      width: 100%;
      border-radius: 0;
      overflow: hidden;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
      z-index: 1001;
      position: relative;
      background: linear-gradient(135deg, #0a0f2c 0%, #000000 100%);
      color: #e0e0e0;
      padding: 40px;
      text-align: center;
    }

    .sensor-header h2 {
      font-size: 2em;
      font-weight: bold;
      margin-bottom: 30px;
      color: #00f7ff;
    }

    .sensor-header p {
      color: rgba(224, 224, 224, 0.8);
      font-size: 1.2em;
      margin-bottom: 30px;
    }

    .sensor-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
      gap: 30px;
      max-width: 1200px;
      margin: 0 auto;
    }

    /* 玻璃拟态设计 */
    .sensor-card {
      background: rgba(10, 15, 44, 0.4);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      /* 细霓虹边框 */
      border: 1px solid rgba(0, 247, 255, 0.3);
      border-radius: 16px;
      padding: 25px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
      transition: all 0.3s ease;
      position: relative;
      overflow: hidden;
    }

    .sensor-card:hover {
      transform: translateY(-5px);
      box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
      border-color: rgba(0, 247, 255, 0.6);
    }

    .sensor-card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 1px;
      /* 霓虹蓝线 */
      background: linear-gradient(90deg, transparent, #00f7ff, transparent);
    }

    .sensor-name {
      font-size: 1.3em;
      font-weight: 500;
      margin-bottom: 15px;
      color: #00f7ff;
    }

    .sensor-value {
      font-size: 2em;
      font-weight: 600;
      margin-bottom: 5px;
      color: #00f7ff;
      font-family: 'Segoe UI', 'Roboto', sans-serif;
      transition: all 0.5s ease;
    }

    .sensor-unit {
      font-size: 1em;
      color: rgba(224, 224, 224, 0.6);
      font-weight: 400;
    }

    .loading-dots::after {
      content: '.';
      animation: dots 1.5s infinite;
    }

    @keyframes dots {
      0%, 20% { content: '.'; }
      40% { content: '..'; }
      60%, 100% { content: '...'; }
    }

    /* 传感器数据采集动画 */
    .sensor-progress-bar {
      height: 4px;
      background: rgba(0, 247, 255, 0.2);
      border-radius: 2px;
      margin-top: 15px;
      overflow: hidden;
    }

    .sensor-progress {
      height: 100%;
      background: linear-gradient(90deg, #00f7ff, #00b3ff);
      width: 0%;
      transition: width 2s ease-in-out;
    }

    #map {
      width: 100%;
      height: 400px;
      border-radius: 10px;
      z-index: 1001;
      position: relative;
      /* 使用深色背景 */
      background-color: rgba(20, 30, 60, 0.8);
      border: 1px solid rgba(0, 247, 255, 0.3);
      box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    }
  </style>
</head>
<body>
  <section class="hero-section">
    <div class="navbar" data-aos="fade-down">
      <div class="logo">灵盔佑驰</div>
      <div class="nav-buttons">
        <button class="login-btn" onclick="window.location.href='index.html'">登录</button>
        <button class="register-btn" onclick="window.location.href='index.html'">注册</button>
      </div>
    </div>
  </section>

  <div class="intro-container" data-aos="fade-up" data-aos-delay="100">
    <div class="intro-header">
      <h2>灵盔佑驰</h2>
      <h2>重新定义骑行安全与效率的智能伙伴</h2>
    </div>
    <div class="intro-content">
      <p>灵盔佑驰是一套专为外卖骑手量身打造的智能头盔系统</p>
      <p>它深度融合先进的物联网与人工智能技术，集成了高精度GPS定位、温湿度环境感知、MPU6050运动姿态检测以及智能语音交互模块，旨在为骑手的每一次出行构建全方位的智能守护</p>
      <p>系统能实时追踪骑手位置，精准识别左转、右转、减速等骑行意图，并能在发生意外摔倒时，第一时间触发紧急警报。</p>
      <p>灵盔佑驰不仅是保障骑手人身安全的坚实盾牌，更是提升配送效率、优化工作体验的智能终端。通过管理后台，运营方能实时掌握骑手状态与周边环境，实现更高效的调度与更及时的应急响应，为整个配送服务体系注入科技动能。</p>
    </div>
  </div>

  <!-- 传感器数据模块 -->
  <div class="sensor-container" data-aos="fade-up" data-aos-delay="200">
    <div class="sensor-header">
      <h2>实时传感器数据</h2>
      <p>智能头盔内置多种传感器，实时监测环境与位置信息</p>
    </div>
    <div class="sensor-grid">
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="300">
        <div class="sensor-name">温度</div>
        <div class="sensor-value" id="temperature">--</div>
        <div class="sensor-unit">°C</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="temperature-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="400">
        <div class="sensor-name">湿度</div>
        <div class="sensor-value" id="humidity">--</div>
        <div class="sensor-unit">%</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="humidity-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="500">
        <div class="sensor-name">经度</div>
        <div class="sensor-value" id="longitude">--</div>
        <div class="sensor-unit">°</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="longitude-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="600">
        <div class="sensor-name">纬度</div>
        <div class="sensor-value" id="latitude">--</div>
        <div class="sensor-unit">°</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="latitude-progress"></div>
        </div>
      </div>
    </div>
  </div>

  <!-- 实时路径追踪模块 -->
  <div class="sensor-container" data-aos="fade-up" data-aos-delay="700">
    <div class="sensor-header">
      <h2>实时路径追踪</h2>
      <p>智能头盔的GPS数据实时上传至管理终端</p>
      <p>管理员可随时查看佩戴者的实时位置与历史轨迹</p>
    </div>
    <div id="map"></div>
  </div>

  <!-- 设备事件监控模块 -->
  <div class="sensor-container" data-aos="fade-up" data-aos-delay="800">
    <div class="sensor-header">
      <h2>设备事件监控</h2>
      <p>实时监控智能头盔检测到的各类事件</p>
    </div>
    <div class="sensor-grid">
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="900">
        <div class="sensor-name">摔倒事件</div>
        <div class="sensor-value" id="fall-events">0</div>
        <div class="sensor-unit">次</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="fall-events-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="1000">
        <div class="sensor-name">减速事件</div>
        <div class="sensor-value" id="slow-events">0</div>
        <div class="sensor-unit">次</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="slow-events-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="1100">
        <div class="sensor-name">左转事件</div>
        <div class="sensor-value" id="left-turn-events">0</div>
        <div class="sensor-unit">次</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="left-turn-events-progress"></div>
        </div>
      </div>
      <div class="sensor-card" data-aos="fade-right" data-aos-delay="1200">
        <div class="sensor-name">右转事件</div>
        <div class="sensor-value" id="right-turn-events">0</div>
        <div class="sensor-unit">次</div>
        <div class="sensor-progress-bar">
          <div class="sensor-progress" id="right-turn-events-progress"></div>
        </div>
      </div>
    </div>
  </div>

  <!-- AOS动画库JS -->
  <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
  <script>
    // 初始化AOS动画
    AOS.init({
      duration: 800,
      easing: 'ease-out-cubic',
      once: true,
      offset: 120
    });
    
    // 设备事件监控数据
    let eventCounts = {
      fall: 0,
      slow: 0,
      leftTurn: 0,
      rightTurn: 0
    };

    // 页面加载完成后初始化地图和传感器数据
    window.onload = function () {
      initMap();
      startSensorDataCollection();
      startEventMonitoring(); // 启动设备事件监控
    };

    // 开始传感器数据采集循环
    function startSensorDataCollection() {
      collectSensorData();
      // 每4秒执行一次数据采集循环（2秒采集+2秒间隔）
      setInterval(collectSensorData, 4000);
    }

    // 传感器数据采集函数
    function collectSensorData() {
      // 显示采集进度动画
      showCollectionProgress();
      
      // 2秒后更新传感器数据
      setTimeout(() => {
        updateSensorData();
      }, 2000);
    }

    // 显示采集进度动画
    function showCollectionProgress() {
      // 重置所有进度条
      const progressBars = document.querySelectorAll('.sensor-progress');
      progressBars.forEach(bar => {
        bar.style.width = '0%';
      });
      
      // 2秒内完成进度条动画
      setTimeout(() => {
        progressBars.forEach(bar => {
          bar.style.width = '100%';
        });
      }, 100);
    }

    // 更新传感器数据
    function updateSensorData() {
      // 模拟传感器数据
      const sensors = [
        { id: 'temperature', name: '温度', unit: '°C', minValue: 20, maxValue: 35 },
        { id: 'humidity', name: '湿度', unit: '%', minValue: 40, maxValue: 80 },
        { id: 'longitude', name: '经度', unit: '°', minValue: 119.29, maxValue: 119.31 },
        { id: 'latitude', name: '纬度', unit: '°', minValue: 26.07, maxValue: 26.09 }
      ];

      sensors.forEach(sensor => {
        const element = document.getElementById(sensor.id);
        const progressElement = document.getElementById(sensor.id + '-progress');
        
        // 移除加载动画类
        element.classList.remove('loading-dots');
        
        // 生成随机数据
        const value = sensor.minValue + Math.random() * (sensor.maxValue - sensor.minValue);
        element.textContent = sensor.id === 'longitude' || sensor.id === 'latitude' ? 
          value.toFixed(6) : 
          Math.round(value);
      });
      
      // 2秒后清空数据
      setTimeout(clearSensorData, 2000);
    }

    // 清空传感器数据
    function clearSensorData() {
      const sensors = ['temperature', 'humidity', 'longitude', 'latitude'];
      
      sensors.forEach(sensorId => {
        const element = document.getElementById(sensorId);
        const progressElement = document.getElementById(sensorId + '-progress');
        
        // 显示加载动画
        element.textContent = '';
        element.classList.add('loading-dots');
        element.innerHTML = '获取中';
        
        // 重置进度条
        progressElement.style.width = '0%';
      });
    }

    // 初始化地图函数
    function initMap() {
      try {
        console.log('开始初始化百度地图...');
        var map = new BMap.Map("map");
        // 福州市中心坐标
        var fuzhouPoint = new BMap.Point(119.296494, 26.074507);
        map.centerAndZoom(fuzhouPoint, 15);
        map.enableScrollWheelZoom(true); // 启用滚轮缩放

        // 示例路径数据（模拟佩戴者移动轨迹，非直线）
        var pathPoints = [
          new BMap.Point(119.290, 26.070), // 起点
          new BMap.Point(119.295, 26.072),
          new BMap.Point(119.300, 26.070), // 折返点
          new BMap.Point(119.305, 26.074),
          new BMap.Point(119.310, 26.072)  // 终点
        ];

        // 存储动态绘制的线段和标记
        let dynamicPolylines = [];
        let dynamicMarkers = [];

        // 添加起点标记
        var startIcon = new BMap.Icon("http://map.baidu.com/img/markers.png", new BMap.Size(24, 24), {
          imageOffset: new BMap.Size(0, 0)
        });

        var startMarker = new BMap.Marker(pathPoints[0], { icon: startIcon });
        map.addOverlay(startMarker);

        // 创建一个移动图标模拟实时位置
        var movingIcon = new BMap.Icon("http://map.baidu.com/img/markers.png", new BMap.Size(24, 24), {
          imageOffset: new BMap.Size(-48, 0)
        });
        var movingMarker = new BMap.Marker(pathPoints[0], { icon: movingIcon });
        map.addOverlay(movingMarker);

        // 平滑移动函数
        function moveSmoothly(startPoint, endPoint, duration) {
          const startTime = new Date().getTime();
          const endTime = startTime + duration;

          function animate() {
            const now = new Date().getTime();
            const progress = Math.min((now - startTime) / duration, 1);
            const lng = startPoint.lng + (endPoint.lng - startPoint.lng) * progress;
            const lat = startPoint.lat + (endPoint.lat - startPoint.lat) * progress;
            movingMarker.setPosition(new BMap.Point(lng, lat));

            if (progress < 1) {
              requestAnimationFrame(animate);
            }
          }

          animate();
        }

        // 循环播放移动动画
        let currentIndex = 0;
        const moveInterval = 1000; // 每1秒移动一次

        function moveNext() {
          if (currentIndex >= pathPoints.length - 1) {
            // 到达终点，清除所有动态绘制的线段和标记
            dynamicPolylines.forEach(polyline => map.removeOverlay(polyline));
            dynamicMarkers.forEach(marker => map.removeOverlay(marker));
            dynamicPolylines = [];
            dynamicMarkers = [];

            // 重新开始
            setTimeout(() => {
              currentIndex = 0;
              movingMarker.setPosition(pathPoints[0]);
            }, 1000);
          } else {
            // 绘制当前线段
            var currentPolyline = new BMap.Polyline([pathPoints[currentIndex], pathPoints[currentIndex + 1]], {
              strokeColor: "#00f7ff",
              strokeWeight: 5,
              strokeOpacity: 0.8
            });
            map.addOverlay(currentPolyline);
            dynamicPolylines.push(currentPolyline);

            // 为下一个点添加标记
            var nextPointIndex = currentIndex + 1;
            var nextMarker = new BMap.Marker(pathPoints[nextPointIndex], { icon: startIcon });
            map.addOverlay(nextMarker);
            dynamicMarkers.push(nextMarker);

            // 平滑移动到下一个点
            moveSmoothly(pathPoints[currentIndex], pathPoints[currentIndex + 1], moveInterval);
            currentIndex++;
          }
        }

        setInterval(moveNext, moveInterval); // 每1秒触发一次移动

        console.log('地图初始化完成');
      } catch (e) {
        console.error('地图初始化失败:', e);
        alert('地图初始化失败，请刷新页面重试');
      }
    }

    // 更新设备事件显示
    function updateEventDisplay() {
      // 更新跌倒事件
      const fallElement = document.getElementById('fall-events');
      fallElement.textContent = eventCounts.fall;
      
      // 更新缓慢运动事件
      const slowElement = document.getElementById('slow-events');
      slowElement.textContent = eventCounts.slow;
      
      // 更新左转事件
      const leftTurnElement = document.getElementById('left-turn-events');
      leftTurnElement.textContent = eventCounts.leftTurn;
      
      // 更新右转事件
      const rightTurnElement = document.getElementById('right-turn-events');
      rightTurnElement.textContent = eventCounts.rightTurn;
      
      // 触发进度条动画
      showEventProgress();
    }

    // 显示事件进度动画
    function showEventProgress() {
      // 重置所有进度条
      const progressBars = document.querySelectorAll('.sensor-progress');
      progressBars.forEach(bar => {
        bar.style.width = '0%';
      });
      
      // 2秒内完成进度条动画
      setTimeout(() => {
        progressBars.forEach(bar => {
          bar.style.width = '100%';
        });
      }, 100);
    }

    // 模拟设备事件数据
    function simulateEventUpdates() {
      // 随机增加事件计数
      if (Math.random() > 0.7) {
        eventCounts.fall++;
      }
      if (Math.random() > 0.5) {
        eventCounts.slow++;
      }
      if (Math.random() > 0.6) {
        eventCounts.leftTurn++;
      }
      if (Math.random() > 0.6) {
        eventCounts.rightTurn++;
      }
      
      // 更新显示
      updateEventDisplay();
    }

    // 启动设备事件监控
    function startEventMonitoring() {
      simulateEventUpdates();
      setInterval(simulateEventUpdates, 3000);
    }
  </script>
</body>
</html>